class Solution {
public:
/*   //计数器
    int MoreThanHalfNum_Solution(vector<int> numbers) {
        int cnt[50000] = {0};
        int len = numbers.size();
        for(int i = 0; i < len; ++i){
            ++cnt[numbers[i]];
        }
        for(int i = 0; i < len; ++i){
            if(cnt[numbers[i]] > len/2){
                return numbers[i];
            }
        }
        return 0;
    }
*/

/* // 题解
    int MoreThanHalfNum_Solution(vector<int> numbers) {
        //无序哈希表统计每个数字出现的次数 fast-template
        unordered_map<int, int> mp;
        //遍历数组
        for(int i = 0; i < numbers.size(); i++){
            //哈希表中相应数字个数加1
            mp[numbers[i]]++;
            //一旦有个数大于长度一半的情况即可返回
            if(mp[numbers[i]] > numbers.size() / 2)
                return numbers[i];
        }
        return 0;
    }
*/
    
    int MoreThanHalfNum_Solution(vector<int> numbers) {
        int cnt[50001] = {0};
        int len = numbers.size();
        for(int i = 0; i < len; ++i){
            ++cnt[numbers[i]];
            if(cnt[numbers[i]] > len/2){
                return numbers[i];
            }
        }
        return 0;
    }
};